"use client";

import {useEffect, useRef} from 'react';
import { message } from 'antd';
import { useRouter } from 'next/navigation';

export default function ErrorToast({ error }: { error: string | null }) {
    const router = useRouter();
    const toastShown = useRef(false);


    useEffect(() => {
        if (error && !toastShown.current) {
            toastShown.current = true;
             message.error({
                content: (
                    <span>
                        {"登录后可查看"}<br/>
                        <small>3秒后自动返回题目列表页</small>
                    </span>
                ),
                duration: 3,
                 onClose: () => {
                     router.push('/questions');
                     toastShown.current = false; // 重置状态
                 },
                className: 'custom-error-toast'
            });
        }
    }, [error, router]); // 确保添加依赖项

    return null; // 不渲染任何DOM元素
}
